/*
 * BSM6.0
 *
 * Copyright 2012-2013 (C) SINODATA CO., LTD. All Rights Reserved.
 */
package com.sinodata.bsm.cicp.service;

import java.io.BufferedReader;

import org.apache.log4j.Logger;

import com.sinodata.bsm.cicp.util.WmiUtil;
import com.sinodata.bsm.common.vo.ProtocolParameter;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author dongyushi
 * @version 1.0

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2012-8-13 上午10:25:53          dongyushi        1.0         To create
 * </p>
 *
 * @since 
 * @see     
 */
public class WmiConnectionService {
    private static final Logger logger = Logger.getLogger(WmiConnectionService.class);
    private static final String SEPARATOR = " <@> ";

    public Boolean testConn(ProtocolParameter protocolParameter) {

        String ip = protocolParameter.getIp();
        String scriptName = "WMI_Test.vbs";
        String strLine = null;
        BufferedReader reader = null;
        boolean flag = false;
        try {
            reader = WmiUtil.execWmiScript(ip, protocolParameter.getUserName(), protocolParameter.getPwd(), scriptName, null);
            while ((strLine = reader.readLine()) != null) {
                //判断返回值是否包含特殊字符
                if (strLine.indexOf(SEPARATOR) > -1) {
                    flag = true;
                    break;
                }
            }
        } catch (Exception e) {
            logger.error(e.getMessage());
        }
        if (flag) {
            return true;
        } else {
            return false;
        }
    }
}
